package com.example.spring_demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@Component("bookDao")//起名称
//@Scope("singleton")单例
@Scope("prototype")   //非单例
public class BookDao {
    @Value("zuomenghao")  //使用@value可以实现简单注入，这个值一般是外部库加载进来的
    private String name;

    public void BookDao(){
        System.out.println("bean..." );
    }
    public void save(){
        System.out.println("book dao save..." +name);
    }

    // 基于注解的bean生命周期
    @PostConstruct
    public void init(){
        System.out.println("init...");
    }
    @PreDestroy
    public void destory(){
        System.out.println("destory...");
    }


}
